cmake_minimum_required(VERSION 3.5)
project(lidar_calibration)

# Default to C++14
if(NOT CMAKE_CXX_STANDARD)
  set(CMAKE_CXX_STANDARD 14)
endif()

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  add_compile_options(-Wall -Wextra -Wpedantic)
endif()

# Find dependencies
find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
find_package(sensor_msgs REQUIRED)
find_package(std_msgs REQUIRED)
find_package(geometry_msgs REQUIRED)
find_package(nav_msgs REQUIRED)
find_package(tf2 REQUIRED)
find_package(tf2_ros REQUIRED)
find_package(tf2_geometry_msgs REQUIRED)
find_package(Eigen3 REQUIRED)
find_package(yaml-cpp REQUIRED)
find_package(tinyxml2_vendor REQUIRED)
find_package(agv_msgs REQUIRED)
find_package(agv_srvs REQUIRED)
find_package(shared_parameters REQUIRED)

find_package(Boost REQUIRED COMPONENTS thread system)

include_directories(
  include
  ${PROJECT_SOURCE_DIR}/include
  ${EIGEN3_INCLUDE_DIR}
  ${YAML_CPP_INCLUDE_DIR}
  ${Boost_INCLUDE_DIRS}  
)

# Map reader library
add_library(map_reader src/map_reader.cpp)
ament_target_dependencies(map_reader
  PUBLIC
  rclcpp
  tinyxml2_vendor
  shared_parameters
)

target_include_directories(map_reader PUBLIC 
  $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
  $<INSTALL_INTERFACE:include>
  ${tinyxml2_vendor_INCLUDE_DIRS}
  ${rclcpp_INCLUDE_DIRS})

target_link_libraries(map_reader PUBLIC tinyxml2)

# Main calibration node
add_executable(lidar_calibration_node 
  src/lidar_calibration.cpp
)

target_link_libraries(lidar_calibration_node
  map_reader
  ${Boost_LIBRARIES} 
)

ament_target_dependencies(lidar_calibration_node
  rclcpp
  sensor_msgs
  std_msgs
  geometry_msgs
  nav_msgs
  tf2
  tf2_ros
  tf2_geometry_msgs
  Eigen3
  yaml-cpp
  tinyxml2_vendor
  agv_msgs
  agv_srvs
)

target_include_directories(lidar_calibration_node PRIVATE
  ${Boost_INCLUDE_DIRS}
)

# Install targets
install(TARGETS 
  lidar_calibration_node
  map_reader
  DESTINATION lib/${PROJECT_NAME}
)

# Install launch files
install(DIRECTORY launch/
  DESTINATION share/${PROJECT_NAME}/launch
)

# Install include files
install(DIRECTORY include/
  DESTINATION include
)

ament_package()